home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************************
- ExampleModule.c
-
-
- DOCUMENTATION
-
- an example module for ScreenLight
- using 68k style globals.
-
-
- MODULE CODE RESOURCES
-
- Here are the types we define for the kinds of Modules one
- might produce.
-
- App: creator='SS-ß'
-
- 68k Only: type='SS-m'
- code='SS-m' 0
-
- PPC Only: type='SS-p',
- std cfrg
-
- Fat Binary: type='SS-f',
- std cfrg
- code='SS-m' 0
-
-
-
- HISTORY
-
- 03jun94 bh New Today
-
- 19jun94 bh Clean up Close code
- added monitor profile code
- added test for Preview Mode
-
- 21aug94 bh CheckRequiredFeatures() added
- 27aug94 bh util CalcHSBtoRGB()
- 28nov95 bh new module interface
-
-
-
- Copyright )WORK-IN_PROGRESS Noesis Software Construction
- **********************************************************************************/
-
- #include "fp.h"
-
- //*********************************************************************************
- // I N C L U D E I N C L U D E S
-
- #include "ModuleRoutines.h"
-
-
- //*********************************************************************************
- // F O R W A R D G L O B A L S
-
- OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr);
-
-
-
- //*********************************************************************************
- // C O N S T A N T S
-
- // use this struct for all of your
- // private data needs !
-
- struct SampleData {
- long useColor;
- long whichColor;
- long lightCnt;
- };
- typedef struct SampleData SampleData;
- typedef SampleData *SampleDataPtr;
-
-
- //*********************************************************************************
- // main - MPW Linker wanted a routine named main.
- //*********************************************************************************
- OSErr main( ModuleParamBlkPtr mpPtr)
- {
- return ModOpen( mpPtr);
- }
-
- //*********************************************************************************
- // ModOpen
- //*********************************************************************************
- OSErr ModOpen( ModuleParamBlkPtr mpPtr)
- {
- OSErr err = noErr;
- SampleDataPtr sData;
- short refNum;
-
- //Debugger();
- if ( (err=InitmProcs(mpPtr)) != noErr)
- return err;
-
- // If you have your own About proc defined, use the following line
- mpPtr->mProcs.aboutProc = NewModAboutProc( ABOUTPROCNAME);
-
- // Check for Features Required...
- if ( (err=CheckRequiredFeatures()) != noErr)
- goto error;
-
-
- // Test for preview,
- if ( mpPtr->mInPreview) {
- ;
- }
-
- // Allocate our private storage
- sData = (SampleDataPtr)NewPtrClear(sizeof(SampleData));
- if (err = MemError()) goto error;
-
- // Set other local variables
- sData->useColor = 0;
- sData->lightCnt = 0;
-
- // Get into our file
- // the Module is the current Resource File during the Open()
- // call, so any and all custom resources are available...
- //
- //resH = Get1Resource( 'tClr', 128);
-
- // store private data in paramBlk
- mpPtr->mStorage = (long)sData;
-
- // done
- return noErr;
-
- error:
- if ( sData) {
- DisposPtr((Ptr)sData);
- }
-
- mpPtr->mStorage = 0;
-
- return err;
- }
-
-
- //*********************************************************************************
- // ModDraw
- //
- // The Port is set for you on entry. Have fun !
- //
- //*********************************************************************************
- #define kMaxPts 100
-
- OSErr ModDraw( ModuleParamBlkPtr mpPtr)
- {
- SampleDataPtr sData;
- short cnt, numLights;
- Point pts[ kMaxPts];
-
- if ( IRandom(1,4) == 4)
- return noErr;
-
- sData = (SampleDataPtr)mpPtr->mStorage;
- numLights = sData->lightCnt;
-
- for ( cnt=0; cnt<numLights; cnt++) {
- pts[cnt].h = IRandom( 0, mpPtr->mGraf->portRect.right);
- pts[cnt].v = IRandom( 0, mpPtr->mGraf->portRect.bottom);
- }
-
- if ( sData->useColor == 0)
- ForeColor( whiteColor);
- else
- ForeColor( sData->whichColor);
-
- for ( cnt=0; cnt<numLights; cnt++) {
- //MoveTo( pts[cnt].h, pts[cnt].v);
- //Line( 0, 0);
- MoveTo( pts[cnt].h-1, pts[cnt].v);
- Line( 0, 0);
- MoveTo( pts[cnt].h+1, pts[cnt].v);
- Line( 0, 0);
- MoveTo( pts[cnt].h, pts[cnt].v-1);
- Line( 0, 0);
- MoveTo( pts[cnt].h, pts[cnt].v+1);
- Line( 0, 0);
- }
-
- ForeColor( blackColor);
- for ( cnt=0; cnt<numLights; cnt++) {
- //MoveTo( pts[cnt].h, pts[cnt].v);
- //Line( 0, 0);
- MoveTo( pts[cnt].h-1, pts[cnt].v);
- Line( 0, 0);
- MoveTo( pts[cnt].h+1, pts[cnt].v);
- Line( 0, 0);
- MoveTo( pts[cnt].h, pts[cnt].v-1);
- Line( 0, 0);
- MoveTo( pts[cnt].h, pts[cnt].v+1);
- Line( 0, 0);
- }
-
- return noErr;
- }
-
-
- //*********************************************************************************
- // ModClose
- //
- // Clean-up after Module Run. Dispose of any storage on the heap.
- // The resource file and Control values are updated automatically.
- //
- //*********************************************************************************
- OSErr ModClose( ModuleParamBlkPtr mpPtr)
- {
- SampleDataPtr data = (SampleDataPtr)mpPtr->mStorage;
- OSErr err = noErr;
-
- if (data != 0) {
- DisposePtr((Ptr)data);
- err = MemError();
- }
-
- return err;
- }
-
-
-
- //*************************************************
- // Sample About Procedure for a Module
-
- OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr)
- {
- Rect tmpR;
- EventRecord evt;
- SampleDataPtr data;
-
- data = (SampleDataPtr)mpPtr->mStorage;
-
- // GrafPort is set on entry
- tmpR = mpPtr->mGraf->portRect;
- EraseRect( &tmpR);
-
- if ( GetPortPixDepth( mpPtr->mGraf) > 1)
- ForeColor( redColor);
- else
- ForeColor( whiteColor);
- PaintRect( &tmpR);
-
- while ( !WaitNextEvent( mDownMask+keyDownMask, &evt, GetCaretTime(), 0))
- ;
-
- ForeColor( blackColor);
- PaintRect( &tmpR);
-
- return;
- }
-
-
- //*************************************************
- OSErr ModChangePrefs( ModuleParamBlkPtr mpPtr)
- {
- SampleDataPtr sData;
- long **tIDh;
- short val;
- OSErr err = noErr;
-
- // We get passed in a ptr to the ModControlRecord in
- // the mInfo fld. Our only clue to which control type
- // this is is by the first long in every ModControlRec,
- // the User-Defined ID number !
-
- sData = (SampleDataPtr)mpPtr->mStorage;
- tIDh = (long**)mpPtr->mInfo;
-
- switch (**tIDh) {
- case 1: // Slider
- {
- ScSLD_SliderRec **tScSLD_RecH;
- // we have a horizSlider
-
- tScSLD_RecH = (ScSLD_SliderRec **)mpPtr->mInfo;
- sData->lightCnt = (*tScSLD_RecH)->curValue;
-
- }
- break;
-
- case 2: // Check Box
- {
- ScCHK_CheckBoxRec **tScCHK_RecH;
- // we have a check box
- // This CheckBox turns color use on and off
-
- // Test to see if we want color allowed
- if ( !IsColorPort( mpPtr->mGraf)
- || GetPortPixDepth( mpPtr->mGraf) < 4)
- return kModDisableControl;
-
- tScCHK_RecH = (ScCHK_CheckBoxRec **)mpPtr->mInfo;
- sData->useColor = (*tScCHK_RecH)->val;
-
- }
- break;
-
- case 3: // Popup/List
- {
- ScLST_ListRec **tScLST_RecH;
- // we have a popup, set value based on hard-wired
- // association with MENU resource in Module Controls.
- // This Popup chooses a drawing color
-
- // Test to see if we want color allowed
- if ( !IsColorPort( mpPtr->mGraf)
- || GetPortPixDepth( mpPtr->mGraf) < 4)
- return kModDisableControl;
-
- tScLST_RecH = (ScLST_ListRec **)mpPtr->mInfo;
- switch ( (*tScLST_RecH)->curValue) {
- case 1: sData->whichColor = cyanColor; break;
- case 2: sData->whichColor = yellowColor; break;
- case 3: sData->whichColor = magentaColor; break;
- case 4: sData->whichColor = whiteColor; break;
- default: break;
- };
-
- }
- break;
-
- case 4: // Button
- {
- ScBTN_ButtonRec **tScBTN_RecH;
- // we have a button
- // this btn msg will be called by the App when init'ing
- // ctls, just to check if we want the button disabled or not.
- // Check the 'isHit' field to see if you have a real btn hit.
-
- tScBTN_RecH = (ScBTN_ButtonRec **)mpPtr->mInfo;
-
- if ( (*tScBTN_RecH)->isHit) {
- // NOTE: if you want explicit or implicit globals
- // like a string literal in double-quotes, on
- // the 68k side, you must add the A4() macros
- // ie "\pButton Title ="
-
- ParamText( 0, (*tScBTN_RecH)->titleStr,0,0);
- CautionAlert( 128, 0);
- }
- }
- break;
-
- };
-
- return noErr;
- }
-
-
-
-
- //**********************************************************************************
- // E N D O F L I S T I N G
-